home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / AmigaSystem / Scalos / GuiGFXLib / src / guigfx_initexit.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  4.1 KB  |  197 lines

  1. /*********************************************************************
  2. ----------------------------------------------------------------------
  3.  
  4.     $VER: guigfx_initexit.c 1.0
  5.     ©1997 Captain Bifat / TEK neoscientists
  6.  
  7. ----------------------------------------------------------------------
  8. *********************************************************************/
  9.  
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. #include <proto/render.h>
  15. #include <proto/dos.h>
  16. #include <render/render.h>
  17. #include <graphics/gfxbase.h>
  18.  
  19. #include "guigfx_global.h"
  20.  
  21.  
  22. /*********************************************************************
  23.  
  24.     GetEnv(name)
  25.     
  26. *********************************************************************/
  27.  
  28. char *GetFileString(char *name)
  29. {
  30.     BPTR fp;
  31.     char *linebuffer = NULL;
  32.  
  33.     if (fp = Open(name, MODE_OLDFILE))
  34.     {
  35.         if (linebuffer = AllocVec(30, MEMF_ANY))
  36.         {
  37.             if (FGets(fp, linebuffer, 30) == NULL)
  38.             {
  39.                 FreeVec(linebuffer);
  40.                 linebuffer = NULL;
  41.             }
  42.         }
  43.         Close(fp);
  44.     }
  45.     return linebuffer;
  46. }
  47.  
  48.  
  49. char *GetEnv(char *name)
  50. {
  51.     char *fnamebuffer;
  52.     char *value = NULL;
  53.     
  54.     if (fnamebuffer = AllocVec(strlen(name) + 30, MEMF_ANY))
  55.     {
  56.         strcpy(fnamebuffer, "ENV:");
  57.         if (AddPart(fnamebuffer, name, strlen(name) + 20))
  58.         {
  59.             value = GetFileString(fnamebuffer);    
  60.         }
  61.         
  62.         if (!value)
  63.         {
  64.             strcpy(fnamebuffer, "ENVARC:");
  65.             if (AddPart(fnamebuffer, name, strlen(name) + 20))
  66.             {
  67.                 value = GetFileString(fnamebuffer);    
  68.             }
  69.         }
  70.     
  71.         FreeVec(fnamebuffer);    
  72.     }
  73.     
  74.     return value;
  75. }
  76.  
  77.  
  78.  
  79. /*********************************************************************
  80.  
  81.     GGFX_Init
  82.     GGFX_Exit
  83.  
  84. *********************************************************************/
  85.  
  86. BOOL LIBENT GGFX_Init(void)
  87. {
  88.     char *env;
  89.  
  90.     UtilityBase = OpenLibrary("utility.library", 37);
  91.     GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 39);
  92.     DataTypesBase = OpenLibrary("datatypes.library", DATATYPES_VERSION);
  93.     CyberGfxBase = OpenLibrary("cybergraphics.library", CYBERGFX_VERSION);
  94.     DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 0);
  95. //    MathTransBase = OpenLibrary("mathtrans.library", 0);
  96.     IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0);
  97.  
  98.     RenderBase = OpenLibrary("render.library", RENDER_VERSION);
  99.     if (!RenderBase)
  100.     {
  101.         RenderBase = OpenLibrary("libs/render.library", RENDER_VERSION);
  102.     }
  103.  
  104.     if (UtilityBase && GfxBase && RenderBase && 
  105.         DOSBase) // && MathTransBase)
  106.     {
  107.         MemHandler = CreateRMHandler(RND_MemType, DEFAULT_RMHTYPE, TAG_DONE);
  108.         if (MemHandler)
  109.         {
  110.             gfx40 = (GfxBase->LibNode.lib_Version >= 40);
  111.  
  112.             if (CyberGfxBase)
  113.             {
  114.                 cgfx41 = (CyberGfxBase->lib_Version >= 41);
  115.                 #ifdef DEBUG
  116.                 if (cgfx41)
  117.                 {
  118.                     DB(kprintf("Cybergraphics v41 detected.\n"));
  119.                 }
  120.                 #endif
  121.  
  122.  
  123.                 //    get env variables
  124.                 
  125.             //    if (env = getenv("guigfx/autoditherthreshold"))
  126.                 if (env = GetEnv("guigfx/autoditherthreshold"))
  127.                 {
  128.                     env_autoditherthreshold = atoi(env);
  129.                 //    free(env);
  130.                     FreeVec(env);
  131.                 }
  132.                 
  133.                 if (cgfx41)
  134.                 {
  135.                 //    if (env = getenv("guigfx/usescalepixelarray"))
  136.                     if (env = GetEnv("guigfx/usescalepixelarray"))
  137.                     {
  138.                         env_usescalepixelarray = (atoi(env) == 1);
  139.                     //    free(env);
  140.                         FreeVec(env);
  141.                     }
  142.                 }
  143.  
  144.             //    if (env = getenv("guigfx/usewpa8"))
  145.                 if (env = GetEnv("guigfx/usewpa8"))
  146.                 {
  147.                     env_usewpa8 = (atoi(env) == 1);
  148.                 //    free(env);
  149.                     FreeVec(env);
  150.                 }
  151.             }
  152.  
  153.             DB(kprintf("autoditherthreshold: %ld, usescalepixelarray: %ld, usewpa8: %ld\n", env_autoditherthreshold, env_usescalepixelarray, env_usewpa8));
  154.  
  155.             return TRUE;
  156.         }
  157.     }
  158.  
  159.     GGFX_Exit();
  160.     return FALSE;
  161.     
  162. }
  163.  
  164. void LIBENT GGFX_Exit(void)
  165. {
  166.     if (MemHandler)
  167.     {
  168.         DeleteRMHandler(MemHandler);        //!! eagleplayer
  169.         MemHandler = NULL;
  170.     }
  171.  
  172.     CloseLibrary(RenderBase);
  173.     RenderBase = NULL;
  174.  
  175.     CloseLibrary((struct Library *) IntuitionBase);
  176.     IntuitionBase = NULL;
  177.  
  178. //    CloseLibrary(MathTransBase);
  179. //    MathTransBase = NULL;
  180.  
  181.     CloseLibrary((struct Library *) DOSBase);
  182.     DOSBase = NULL;
  183.  
  184.     CloseLibrary(CyberGfxBase);
  185.     CyberGfxBase = NULL;
  186.  
  187.     CloseLibrary(DataTypesBase);
  188.     DataTypesBase = NULL;
  189.  
  190.     CloseLibrary((struct Library *) GfxBase);
  191.     GfxBase = NULL;
  192.  
  193.     CloseLibrary(UtilityBase);
  194.     UtilityBase = NULL;
  195.     
  196. }
  197.